#include "helper.h"
#include "monitor.h"
#include "reg.h"

extern uint32_t instr;
extern char assembly[80];

static uint32_t get_imm(uint32_t instr){
    return instr & 0x3ffffff;
}

make_helper(j){
    cpu.pc = (cpu.pc & 0xf0000000) + ((get_imm(instr)) << 2);
    sprintf(assembly, "j    0x%08x ",cpu.pc);
    cpu.pc -= 4;
}

make_helper(jal){
    reg_w(31) = cpu.pc + 8;
    cpu.pc = (cpu.pc & 0xf0000000) + ((get_imm(instr)) << 2);
    sprintf(assembly, "jal    %d",cpu.pc);
    cpu.pc -= 4;
}